﻿using System;
using System.Web;
using iSun.Web.UI.Controls;

namespace iSun.WebApp.Extend.AjaxData
{
    public partial class WorkFlowTask : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string strAction = this.GetStringFromQueryString("action", "");
            string strOperatorInstanceId = this.GetStringFromQueryString("operatorInstanceId", "");
            switch (strAction)
            {
                case "taskFlow":
                    TaskClaim(this.User.LoginName,strOperatorInstanceId);
                    break;
                case "taskUnFlow":
                    TaskUnClaim(this.User.LoginName, strOperatorInstanceId);
                    break;
                default:
                    break;
            }
        }
        /// <summary>
        /// 认领操作
        /// </summary>
        /// <param name="loginName">登录名</param>
        /// <param name="operatorInstanceId">操作实例ID</param>
        private void TaskClaim(string loginName, string operatorInstanceId) {
            CrmWorkFlowService.WorkFlowServiceClient client = new CrmWorkFlowService.WorkFlowServiceClient();
            if (client.TaskClaim(loginName, operatorInstanceId) == "000000")
            {
                HttpContext.Current.Response.Write("1");
            }
            else
            {
                HttpContext.Current.Response.Write("0");     
            }
        }
        /// <summary>
        /// 放弃认领操作
        /// </summary>
        /// <param name="loginName">登录名</param>
        /// <param name="operatorInstanceId">操作实例ID</param>
        private void TaskUnClaim(string loginName, string operatorInstanceId)
        {
            CrmWorkFlowService.WorkFlowServiceClient client = new CrmWorkFlowService.WorkFlowServiceClient();
            if (client.TaskUnClaim(loginName, operatorInstanceId) == "000000")
            {
                HttpContext.Current.Response.Write("1");
            }
            else
            {
                HttpContext.Current.Response.Write("0");
            }
        }
    }
}